package com.example.manager.controller;

import com.example.manager.service.SysMenuService;
import com.example.model.dto.system.SysMenuDto;
import com.example.model.entity.system.SysMenu;
import com.example.model.vo.common.Result;
import com.example.model.vo.common.ResultCodeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Api(tags = "菜单管理")
@RestController
@RequestMapping(value = "/admin/system/menu")
public class SysMenuController {

     @Autowired
     private SysMenuService sysMenuService;

    @ApiOperation("查询所有菜单")
    @GetMapping("/findNodes")
    @ApiImplicitParam(name = "token", value = "token值", dataType = "String", paramType = "header")
    public Result findNodes() {
        List<SysMenu> list = sysMenuService.findNodes();
        return Result.build(list, ResultCodeEnum.SUCCESS);
    }

    //新增或者修改菜单
    @ApiOperation(value = "新增或者修改")
    @PostMapping("/saveOrUpdateMenu")
    @ApiImplicitParam(name = "token", value = "token值", dataType = "String", paramType = "header")
    public Result saveOrUpdateMenu(@RequestBody SysMenuDto sysMenuDto) {
        SysMenu sysMenu = new SysMenu();
        BeanUtils.copyProperties(sysMenuDto, sysMenu);
        sysMenuService.saveOrUpdate(sysMenu);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    //删除菜单
    @ApiOperation(value = "删除菜单")
    @DeleteMapping("/deleteMenu/{id}")
    @ApiImplicitParam(name = "token", value = "token值", dataType = "String", paramType = "header")
    public Result deleteMenu(@PathVariable Long id) {
        sysMenuService.deleteMenu(id);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }


}
